#include "../include/rpc_server.h"
#include "../include/conf_reader.h"
#include "../include/chat_service_rpc_server.h"

void rpc_server::start()
{
    server=build.BuildAndStart();
    server->Wait();
    
}

void rpc_server::stop()
{
    server->Shutdown();

}

rpc_server::rpc_server(){
    std::string ip_port=conf_reader::get_conf_reader_instance()->get_value_from_key("rpc_service_address","192.168.174.139:12346");
    build.AddListeningPort(ip_port,grpc::InsecureServerCredentials());
    //注册服务
    register_service();
}


void rpc_server::register_service()
{
    this->chat_rpc_server=new chat_service_rpc_server();
    build.RegisterService(chat_rpc_server);
}

rpc_server::~rpc_server()
{
    //销毁掉注册的服务
    delete chat_rpc_server;
}